﻿using MediatR;
using S.Produce.Domains;
using S.Produce.Infrastructure;
using S.Produce.Read.Api.Application.Commands.DeliveryCommands;

namespace S.Produce.Read.Api.Application.CommandHandlers.DeliveryCommandHandlers
{
    /// <summary>
    /// 根据耳号查找种母分娩信息
    /// </summary>
    public class DeliveryEarselCommandHandler : IRequestHandler<DeliveryEarselCommand, List<Delivery>>
    {
        private readonly IRepository<Delivery> repository;

        /// <summary>
        /// 构造方式注入
        /// </summary>
        /// <param name="repository"></param>
        public DeliveryEarselCommandHandler(IRepository<Delivery> repository)
        {
            this.repository = repository;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<List<Delivery>> Handle(DeliveryEarselCommand request, CancellationToken cancellationToken)
        {
            var info = await repository.SelAllAsync(x => x.Earbugles.Equals(request.EarNumber));
            return info.Where(x => !x.IsDel).ToList();
        }
    }
}
